text view: Fix selection bubble handling
authorMatthias Clasen <mclasen@redhat.com>
Mon, 10 Jun 2019 21:39:14 +0000 (21:39 +0000)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 11 Jun 2019 17:45:55 +0000 (17:45 +0000)
We can't call gtk_widget_destroy on something
that wasn't added as a child to a container -
it ends up calling gtk_container_remove, which
asserts if it doesn't find the child.

gtk/gtktextview.c

index 865b3000496633fc7dbef8468d4594e13104cc5c..6e87b25f23d6526a948d2d5dfe6d5869ad2fe092 100644 (file)
@@ -3635,8 +3635,7 @@ gtk_text_view_finalize (GObject *object)
   if (priv->bottom_window)
     text_window_free (priv->bottom_window);
 
-  if (priv->selection_bubble)
-    gtk_widget_destroy (priv->selection_bubble);
+  g_clear_pointer (&priv->selection_bubble, gtk_widget_unparent);
 
   if (priv->magnifier_popover)
     gtk_widget_destroy (priv->magnifier_popover);
@@ -8796,8 +8795,7 @@ gtk_text_view_selection_bubble_popup_show (gpointer user_data)
   all_selected = gtk_text_iter_equal (&start, &sel_start) &&
                  gtk_text_iter_equal (&end, &sel_end);
 
-  if (priv->selection_bubble)
-    gtk_widget_destroy (priv->selection_bubble);
+  g_clear_pointer (&priv->selection_bubble, gtk_widget_unparent);
 
   priv->selection_bubble = gtk_popover_new (GTK_WIDGET (text_view));
   gtk_style_context_add_class (gtk_widget_get_style_context (priv->selection_bubble),